package org.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.bean.O2rankrank;
import org.dao.CapableDao;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class CapableDaoImpl extends HibernateDaoSupport implements CapableDao {

	

	
	
	
	@SuppressWarnings("rawtypes")
	public List queryForPageCapable(final String hql,final int offset,final int length){   
		List list = getHibernateTemplate().executeFind(new HibernateCallback(){   
		public Object doInHibernate(Session session) throws HibernateException,SQLException{  
			Query query = session.createQuery(hql);
			query.setFirstResult(offset);   
			query.setMaxResults(length);  

			List list = query.list(); 
			
			return list;}   
		});
		return list;		
}
	
	
	public int getAllRowCount(String hql) {
		return getHibernateTemplate().find(hql).size();
	}


	@SuppressWarnings("unchecked")
	@Override
	public O2rankrank selectbyuid(int uid) {
		
		
		String hql ="from O2rankrank o2rank where o2rank.old='旧' and o2rank.uid = "+uid+" order by o2rank.capable desc ";
		List<O2rankrank> o2rankrank = (List<O2rankrank>)this.getHibernateTemplate().find(hql);
		if(o2rankrank.size()!=0){
			return o2rankrank.get(0);
		}
		else{
		return null;
		}
	}
	
}

	

